<template>
	<view class="pad20T pad50B clearfix overflow-x-hidden">
		<uni-steps active-color="#f83d38" :options="[{title: '保费试算'}, {title: '补充资料'}, {title: '身份验证'}, {title: '更新资料'}, {title: '完成投保'}]"
			:active="3"></uni-steps>
		<uni-section class="pub-title" title="订单详情" type="line"></uni-section>
		
		<uni-card class="card-pub" :title="carInfo.name" :isShadow="true">
			<uni-row>
				<uni-col :span="12">
					初登日期: {{baseInfo.chudrq}}
				</uni-col>
				<uni-col :span="12">
					行驶里程: {{baseInfo.xingslc}} 公里
				</uni-col>
			</uni-row>
		</uni-card>
		
		<uni-card title="核心保障" mode="title" :extra="hexbz" note="Tips" :isShadow="true">
			<uni-row class="block-margin">
				<uni-col :span="12">
					赔付限额
				</uni-col>
				<uni-col :span="12">
					<view class="clearfix text-right" decode="true">{{carInfo.price}}&nbsp;万</view>
				</uni-col>
			</uni-row>
			
			<uni-row v-if="taocList.length > 0">
				<uni-col :span="12">
					会员福利
				</uni-col>
				<uni-col class="text-right" :span="12">
					<view class="clearfix text-right">
						<uni-row class="text-right opacity8 margin10B" v-for="(item,index) in taocList">
							{{item.xiangmmc}}, {{item.shuom}}
						</uni-row>
					</view>
				</uni-col>
			</uni-row>
		
			<template v-slot:footer>
				<view>
					<uni-row>
						<uni-col :span="12" class="marign10T">
							售价
						</uni-col>
						<uni-col :span="12">
							<view class="clearfix text-right" decode="true">
								<span class="font-orange-num">{{felb.premium}}&nbsp;元</span>
							</view>
						</uni-col>
					</uni-row>
				</view>
			</template>
		</uni-card>
		
		<uni-section class="pub-title" title="投保人信息" type="line"></uni-section>
		<uni-card class="box-shadow-10 card-pub" :isShadow="true">
			<uni-forms-item label="姓名" name="name">
				<uni-easyinput type="text" v-model="formData.name" placeholder="请输入姓名" :inputBorder="true" disabled="true" />
			</uni-forms-item>
			<uni-forms-item label="手机号码" name="mobile">
				<uni-easyinput type="text" v-model="formData.mobile" placeholder="请输入手机号码" :inputBorder="true" disabled="true" />
			</uni-forms-item>
			<uni-forms-item label="身份证号" name="zhengjhm">
				<uni-easyinput type="text" v-model="formData.zhengjhm" placeholder="请输入身份证号" :inputBorder="true" disabled="true" />
			</uni-forms-item>
			<uni-forms-item label="电子邮箱" name="email">
				<uni-easyinput type="text" v-model="formData.email" placeholder="接收电子保单用" :inputBorder="true" disabled="true" />
			</uni-forms-item>
		</uni-card>
		
		<uni-section class="pub-title" title="车辆信息" type="line"></uni-section>
		<uni-card class="box-shadow-10 card-pub" :isShadow="true">
			<uni-forms-item label="车牌号" name="cheph">
				<uni-easyinput type="text" v-model="formData.cheph" placeholder="请输入车牌号" :inputBorder="true" disabled="true" />
			</uni-forms-item>
			<uni-forms-item label="车架号" name="chejh">
				<uni-easyinput type="text" v-model="formData.chejh" placeholder="请输入车架号" :inputBorder="true" disabled="true" />
			</uni-forms-item>
			<uni-forms-item label="发动机号" name="fadjh">
				<uni-easyinput type="text" v-model="formData.fadjh" placeholder="请输入发动机号" :inputBorder="true" disabled="true" />
			</uni-forms-item>
			<uni-forms-item label="核保图片">
				<u-upload width="160" height="160" :file-list="fileList" max-count="2" :deletable="false"></u-upload>
			</uni-forms-item>
			
		</uni-card>
		
		<button @click="submitForm" class="btn-red bottom-btn border-no">更新资料</button>
		
	</view>
</template>

<script>
	export default {
		data() {
			return {
				hexbz: uni.getStorageSync("baseInfo").level2Sku_fy + ", " + uni.getStorageSync("baseInfo").level4Sku_fy,
				fileList: [
					{
						url: uni.getStorageSync("toubrxx").xingsz
					},
					{
						url: uni.getStorageSync("toubrxx").yibp
					}
				],
				taocList: uni.getStorageSync("taocList"),
				baseInfo: uni.getStorageSync("baseInfo"),
				carInfo: uni.getStorageSync("carInfo"),
				felb: uni.getStorageSync("feilb"),
				product: uni.getStorageSync("product"),
				formData: {
					name: uni.getStorageSync("toubrxx").name,
					mobile: uni.getStorageSync("userInfo").phone,
					email: uni.getStorageSync("toubrxx").email,
					chejh: uni.getStorageSync("carInfo").vin,
					zhengjhm: uni.getStorageSync("toubrxx").zhengjhm,
					cheph: uni.getStorageSync("carInfo").cheph,
					fadjh: uni.getStorageSync("carInfo").fadjh,
				},
			}
		},
		
		onUnload() {
			// wx.navigateTo({
			// 	url: '/pages/baofShis/baofShis'
			// })
			
		},
		
		methods: {
			submitForm: function(form) {
				let that = this
				let order = uni.getStorageSync("selectedOrder")
				
				// 行驶证照片
				order.kuybOrderPolicyList[0].xingsz = uni.getStorageSync("toubrxx").xingsz,
				// 仪表盘照片
				order.kuybOrderPolicyList[0].yibp= uni.getStorageSync("toubrxx").yibp
				// 被保险人地址
				order.kuybOrderPolicyList[0].beibxrdz= uni.getStorageSync("toubrxx").province + "/" + uni.getStorageSync("toubrxx").city + "/" + uni.getStorageSync("toubrxx").county + "/" + uni.getStorageSync("toubrxx").address
				// 使用性质
				order.kuybOrderPolicyList[0].shiyxz= uni.getStorageSync("carInfo").shiyxz
				// 被保险人姓名
				order.kuybOrderPolicyList[0].beibxr= uni.getStorageSync("toubrxx").name
				// 被保险人姓
				order.kuybOrderPolicyList[0].beibxrX= uni.getStorageSync("toubrxx").xing
				// 被保险人名
				order.kuybOrderPolicyList[0].beibxrM= uni.getStorageSync("toubrxx").ming
				// 被保险人联系电话
				order.kuybOrderPolicyList[0].beibxrlxdh= uni.getStorageSync("toubrxx").mobile
				// 被保险人身份证
				order.kuybOrderPolicyList[0].beibxrsfz= uni.getStorageSync("toubrxx").zhengjhm
				// 被保险人邮箱
				order.kuybOrderPolicyList[0].beibxryx= uni.getStorageSync("toubrxx").email
				// 车架号
				order.kuybOrderPolicyList[0].chejh= uni.getStorageSync("carInfo").vin
				// 发动机号
				order.kuybOrderPolicyList[0].fadjh= uni.getStorageSync("carInfo").fadjh
				// 车型id
				order.kuybOrderPolicyList[0].carid= uni.getStorageSync("carInfo").carid
				// 电子签章
				order.userToken = uni.getStorageSync("shenfyz_token")
				
				uni.showLoading({
				    title: '生成合同中...'
				})
				uni.request({
					url: getApp().globalData.serviceUrl + "/order/kuybOrder/edit",
					data: order,
					header: {
						"X-Access-Token": uni.getStorageSync("token")
					},
					method: 'PUT',
					dataType: 'json',
					success: (resp) => {
						uni.hideLoading()
						
						if (resp.data.success) {
							uni.redirectTo({
								url: '/pages/paymentSuccess/paymentSuccess'
							})
							
						} else {
							uni.showToast({
								title: resp.data.message,
								icon: 'none',
								duration: 3000
							});
						}
					},
					complete() {
						uni.hideLoading()
					}
				});
				
				
			}
		}
	}
</script>

<style>

</style>
